package com.cosmoplat.xikai.framework.aspectj;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @ClassName ApiLoggingAspect
 * @Description 日志打印
 * @Author wdf
 * @Date 2025/1/10
 */
@Aspect
@Component
@Slf4j
public class ApiLoggingAspect {

    @Pointcut("execution(* com.cosmoplat.xikai.business.controller..*(..))")
    public void apiEndpoint() {
    }

    @Before("apiEndpoint()")
    public void logRequest(JoinPoint joinPoint) {
        // 打印请求参数
        log.debug("[Request]: " + Arrays.toString(joinPoint.getArgs()));
    }

    @AfterReturning(pointcut = "apiEndpoint()", returning = "result")
    public void logResponse(Object result) {
        // 打印返回结果
        log.debug("[Response]: " + result);
    }
}
